package biblioteca;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import servidor.ServidorRMI;

public class UtilidadesBD 
{
	static private Connection con;
	static private Statement stmt;
	static private ResultSet rs; 
	static private UtilidadesBD BD;
	
	public UtilidadesBD()
	{
		stmt=getStmt();
	}
	
	public static UtilidadesBD getInstance() throws RemoteException 
	{
		if(BD == null)
		{
			BD = new UtilidadesBD();
		}
		return BD;
	}
	
	public static void conectar()
  	{
  		try
  		{
  			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  			 con = DriverManager.getConnection("jdbc:odbc:Biblioteca");
  			 setStmt(con.createStatement());
  			
  		}catch( Exception e)
  		{
  			System.out.println(e.getMessage());
  		}
  	
  	}
	
	public static void desconectarBD()
	{
			
		try 
		{
			stmt.close();
			con.close();
		} 
			
		catch (SQLException e) 
		{
					e.printStackTrace();
			}

	
	}

	public static Statement createStatement() throws SQLException
	{
		return  stmt=con.createStatement();
	}

	public static  void setStmt(Statement stmt) 
	{
		UtilidadesBD.stmt = stmt;
	}

	public static Statement getStmt() 
	{
		return stmt;
	}

	public static void setRs(ResultSet rs)
	{
		UtilidadesBD.rs = rs;
	}

	public static ResultSet getRs() 
	{
		return rs;
	}

	
}
	
